/*
 *  PKL 51 GUNUNG KIDUL
 *  Subseksie DATA ENTRY + CAPI
 */
package pkl51.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import pkl51.error.EntityException;

/**
 *
 * @author Hindarwan
 */
public class ListBlok4Model implements Serializable {

    private static ListBlok4Model instance;
    private static final long serialVersionUID = -1172481865473428509L;
    private List<Blok4RowModel> listBlok4;
    private int jumlahART = 15; //max

    public static ListBlok4Model getInstance() {
        if (instance == null) {
            instance = new ListBlok4Model();
        }
        return instance;
    }

    public ListBlok4Model() {
        listBlok4 = new ArrayList<Blok4RowModel>();
    }

    public void add(Blok4RowModel blok4RowModel) {
        listBlok4.add(blok4RowModel);
    }

    public void insertAllBlok4() throws EntityException {
//        cekEmpty();
        jumlahART = Integer.valueOf(Blok123Model.getInstance().getB2R1());
        for (int i = 0; i < jumlahART; i++) {
            try {
                listBlok4.get(i).insertBlok4Row();
            } catch (NullPointerException ex) {
            }
        }
    }

    public void updateAllBlok4() throws EntityException {
//        cekEmpty();
        jumlahART = Integer.valueOf(Blok123Model.getInstance().getB2R1());
        for (int i = 0; i < jumlahART; i++) {
            try {
                listBlok4.get(i).updateBlok4Row();
            } catch (NullPointerException ex) {
            }
        }

    }

    public void getAllBlok4() throws EntityException {
        for (int i = 0; i < 15; i++) {
            try {
                listBlok4.get(i).setB4C1(String.valueOf(i + 1));
                listBlok4.get(i).getBlok4Row();
            } catch (NullPointerException ex) {
            }
        }
    }

    public void resetModel() {
        for (Blok4RowModel blok4RowModel : listBlok4) {
            blok4RowModel.resetModel();
        }
    }
//    public void cekEmpty() {
//        for (int i = 14; i >= 0; i--) {
//            if ("".equals(listBlok4.get(i).getB4C2()) || listBlok4.get(i).getB4C2() == null) {
//                jumlahART--;
//            } else {
//                break;
//            }
//        }
//    }
}
